<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
                   http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.4.xsd">
    <changeSet id="2022-01-03-init-core-ddl" author="bchernysh">
        <!--core_locales-->
        <createTable tableName="core_locales">
            <column name="id" type="varchar(36)">
                <constraints primaryKey="true" primaryKeyName="core_locales_pk"/>
            </column>
            <column name="config_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="name" type="varchar(50)">
                <constraints nullable="false" unique="true" uniqueConstraintName="core_locales_name_uk"/>
            </column>
            <column name="display_name" type="varchar(50)"/>
            <column name="generation" type="int" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="major_rev" type="varchar(50)" defaultValue="A">
                <constraints nullable="false"/>
            </column>
            <column name="minor_rev" type="varchar(50)"/>
            <column name="is_current" type="tinyint" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="permission_id" type="varchar(36)"/>
            <column name="locale" type="varchar(50)">
                <constraints foreignKeyName="core_locales_locale_fk" references="core_locales(name)"/>
            </column>
            <column name="lifecycle_id" type="varchar(36)"/>
            <column name="state" type="varchar(50)"/>
            <column name="created_at" type="datetime">
                <constraints nullable="false"/>
            </column>
            <column name="created_by_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="updated_at" type="datetime"/>
            <column name="updated_by_id" type="varchar(36)"/>
            <column name="locked_by_id" type="varchar(36)"/>
        </createTable>

<!--        <createIndex tableName="core_locales" indexName="core_locales_config_idx">-->
<!--            <column name="config_id"/>-->
<!--        </createIndex>-->

        <createIndex tableName="core_locales" indexName="core_locales_permission_idx">
            <column name="permission_id"/>
        </createIndex>

<!--        <createIndex tableName="core_locales" indexName="core_locales_major_rev_idx">-->
<!--            <column name="major_rev"/>-->
<!--        </createIndex>-->

<!--        <createIndex tableName="core_locales" indexName="core_locales_is_current_idx">-->
<!--            <column name="is_current"/>-->
<!--        </createIndex>-->

        <!--core_lifecycles-->
        <createTable tableName="core_lifecycles">
            <column name="id" type="varchar(36)">
                <constraints primaryKey="true" primaryKeyName="core_lifecycles_pk"/>
            </column>
            <column name="config_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="name" type="varchar(50)">
                <constraints nullable="false" unique="true" uniqueConstraintName="core_lifecycles_name_uk"/>
            </column>
            <column name="display_name" type="varchar(50)"/>
            <column name="description" type="varchar(250)"/>
            <column name="icon" type="varchar(50)"/>
            <column name="implementation" type="varchar(250)"/>
            <column name="spec" type="text">
                <constraints nullable="false"/>
            </column>
            <column name="checksum" type="varchar(50)"/>
            <column name="hash" type="varchar(50)"/>
            <column name="generation" type="int" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="major_rev" type="varchar(50)" defaultValue="A">
                <constraints nullable="false"/>
            </column>
            <column name="minor_rev" type="varchar(50)"/>
            <column name="is_current" type="tinyint" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="permission_id" type="varchar(36)"/>
            <column name="locale" type="varchar(50)">
                <constraints foreignKeyName="core_lifecycles_locale_fk" references="core_locales(name)"/>
            </column>
            <column name="lifecycle_id" type="varchar(36)">
                <constraints foreignKeyName="core_lifecycles_lifecycle_fk" references="core_lifecycles(id)"/>
            </column>
            <column name="state" type="varchar(50)"/>
            <column name="created_at" type="datetime">
                <constraints nullable="false"/>
            </column>
            <column name="created_by_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="updated_at" type="datetime"/>
            <column name="updated_by_id" type="varchar(36)"/>
            <column name="locked_by_id" type="varchar(36)"/>
        </createTable>

<!--        <createIndex tableName="core_lifecycles" indexName="core_lifecycles_config_idx">-->
<!--            <column name="config_id"/>-->
<!--        </createIndex>-->

        <createIndex tableName="core_lifecycles" indexName="core_lifecycles_permission_idx">
            <column name="permission_id"/>
        </createIndex>

<!--        <createIndex tableName="core_lifecycles" indexName="core_lifecycles_major_rev_idx">-->
<!--            <column name="major_rev"/>-->
<!--        </createIndex>-->

<!--        <createIndex tableName="core_lifecycles" indexName="core_lifecycles_is_current_idx">-->
<!--            <column name="is_current"/>-->
<!--        </createIndex>-->

        <!--core_revision_policies-->
        <createTable tableName="core_revision_policies">
            <column name="id" type="varchar(36)">
                <constraints primaryKey="true" primaryKeyName="core_revision_policies_pk"/>
            </column>
            <column name="config_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="name" type="varchar(50)">
                <constraints nullable="false" unique="true" uniqueConstraintName="core_revision_policies_name_uk"/>
            </column>
            <column name="display_name" type="varchar(50)"/>
            <column name="revisions" type="text">
                <constraints nullable="false"/>
            </column>
            <column name="generation" type="int" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="major_rev" type="varchar(50)" defaultValue="A">
                <constraints nullable="false"/>
            </column>
            <column name="minor_rev" type="varchar(50)"/>
            <column name="is_current" type="tinyint" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="permission_id" type="varchar(36)"/>
            <column name="locale" type="varchar(50)">
                <constraints foreignKeyName="core_revision_policies_locale_fk" references="core_locales(name)"/>
            </column>
            <column name="lifecycle_id" type="varchar(36)">
                <constraints foreignKeyName="core_revision_policies_lifecycle_fk" references="core_lifecycles(id)"/>
            </column>
            <column name="state" type="varchar(50)"/>
            <column name="created_at" type="datetime">
                <constraints nullable="false"/>
            </column>
            <column name="created_by_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="updated_at" type="datetime"/>
            <column name="updated_by_id" type="varchar(36)"/>
            <column name="locked_by_id" type="varchar(36)"/>
        </createTable>

<!--        <createIndex tableName="core_revision_policies" indexName="core_revision_policies_config_idx">-->
<!--            <column name="config_id"/>-->
<!--        </createIndex>-->

        <createIndex tableName="core_revision_policies" indexName="core_revision_policies_permission_idx">
            <column name="permission_id"/>
        </createIndex>

<!--        <createIndex tableName="core_revision_policies" indexName="core_revision_policies_major_rev_idx">-->
<!--            <column name="major_rev"/>-->
<!--        </createIndex>-->

<!--        <createIndex tableName="core_revision_policies" indexName="core_revision_policies_is_current_idx">-->
<!--            <column name="is_current"/>-->
<!--        </createIndex>-->

        <!--core_datasources-->
        <createTable tableName="core_datasources">
            <column name="id" type="varchar(36)">
                <constraints primaryKey="true" primaryKeyName="core_datasources_pk"/>
            </column>
            <column name="config_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="name" type="varchar(50)">
                <constraints nullable="false" unique="true" uniqueConstraintName="core_datasources_name_uk"/>
            </column>
            <column name="connection_string" type="varchar(100)">
                <constraints nullable="false"/>
            </column>
            <column name="username" type="varchar(50)">
                <constraints nullable="false"/>
            </column>
            <column name="passwd" type="varchar(50)">
                <constraints nullable="false"/>
            </column>
            <column name="max_pool_size" type="int"/>
            <column name="min_idle" type="int"/>
            <column name="params" type="text" defaultValue="{}">
                <constraints nullable="false"/>
            </column>
            <column name="generation" type="int" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="major_rev" type="varchar(50)" defaultValue="A">
                <constraints nullable="false"/>
            </column>
            <column name="minor_rev" type="varchar(50)"/>
            <column name="is_current" type="tinyint" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="permission_id" type="varchar(36)"/>
            <column name="locale" type="varchar(50)">
                <constraints foreignKeyName="core_datasources_locale_fk" references="core_locales(name)"/>
            </column>
            <column name="lifecycle_id" type="varchar(36)">
                <constraints foreignKeyName="core_datasources_lifecycle_fk" references="core_lifecycles(id)"/>
            </column>
            <column name="state" type="varchar(50)"/>
            <column name="created_at" type="datetime">
                <constraints nullable="false"/>
            </column>
            <column name="created_by_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="updated_at" type="datetime"/>
            <column name="updated_by_id" type="varchar(36)"/>
            <column name="locked_by_id" type="varchar(36)"/>
        </createTable>

        <!--core_item_templates-->
        <createTable tableName="core_item_templates">
            <column name="id" type="varchar(36)">
                <constraints primaryKey="true" primaryKeyName="core_item_templates_pk"/>
            </column>
            <column name="config_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="name" type="varchar(50)">
                <constraints nullable="false" unique="true" uniqueConstraintName="core_item_templates_name_uk"/>
            </column>
            <column name="plural_name" type="varchar(50)">
                <constraints nullable="false"/>
            </column>
            <column name="core" type="tinyint"/>
            <column name="spec" type="text" defaultValue="{}">
                <constraints nullable="false"/>
            </column>
            <column name="checksum" type="varchar(50)"/>
            <column name="hash" type="varchar(50)"/>
            <column name="generation" type="int" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="major_rev" type="varchar(50)" defaultValue="A">
                <constraints nullable="false"/>
            </column>
            <column name="minor_rev" type="varchar(50)"/>
            <column name="is_current" type="tinyint" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="permission_id" type="varchar(36)"/>
            <column name="locale" type="varchar(50)">
                <constraints foreignKeyName="core_item_templates_locale_fk" references="core_locales(name)"/>
            </column>
            <column name="lifecycle_id" type="varchar(36)">
                <constraints foreignKeyName="core_item_templates_lifecycle_fk" references="core_lifecycles(id)"/>
            </column>
            <column name="state" type="varchar(50)"/>
            <column name="created_at" type="datetime">
                <constraints nullable="false"/>
            </column>
            <column name="created_by_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="updated_at" type="datetime"/>
            <column name="updated_by_id" type="varchar(36)"/>
            <column name="locked_by_id" type="varchar(36)"/>
        </createTable>

<!--        <createIndex tableName="core_item_templates" indexName="core_item_templates_config_idx">-->
<!--            <column name="config_id"/>-->
<!--        </createIndex>-->

        <createIndex tableName="core_item_templates" indexName="core_item_templates_permission_idx">
            <column name="permission_id"/>
        </createIndex>

<!--        <createIndex tableName="core_item_templates" indexName="core_item_templates_major_rev_idx">-->
<!--            <column name="major_rev"/>-->
<!--        </createIndex>-->

<!--        <createIndex tableName="core_item_templates" indexName="core_item_templates_is_current_idx">-->
<!--            <column name="is_current"/>-->
<!--        </createIndex>-->

        <!--core_items-->
        <createTable tableName="core_items">
            <column name="id" type="varchar(36)">
                <constraints primaryKey="true" primaryKeyName="core_items_pk"/>
            </column>
            <column name="config_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="name" type="varchar(50)">
                <constraints nullable="false" unique="true" uniqueConstraintName="core_items_name_uk"/>
            </column>
            <column name="display_name" type="varchar(50)">
                <constraints nullable="false"/>
            </column>
            <column name="plural_name" type="varchar(50)">
                <constraints nullable="false"/>
            </column>
            <column name="display_plural_name" type="varchar(50)">
                <constraints nullable="false"/>
            </column>
            <column name="datasource_id" type="varchar(36)">
                <constraints foreignKeyName="core_items_datasource_fk" references="core_datasources(id)"/>
            </column>
            <column name="table_name" type="varchar(50)"/>
            <column name="query" type="text"/>
            <column name="cache_ttl" type="int"/>
            <column name="title_attribute" type="varchar(50)">
                <constraints nullable="false"/>
            </column>
            <column name="include_templates" type="text" defaultValue='["default"]'>
                <constraints nullable="false"/>
            </column>
            <column name="description" type="varchar(250)"/>
            <column name="icon" type="varchar(50)"/>
            <column name="read_only" type="tinyint"/>
            <column name="core" type="tinyint"/>
            <column name="perform_ddl" type="tinyint"/>
            <column name="versioned" type="tinyint"/>
            <column name="manual_versioning" type="tinyint"/>
            <column name="revision_policy_id" type="varchar(36)">
                <constraints foreignKeyName="core_items_revision_policy_fk" references="core_revision_policies(id)"/>
            </column>
            <column name="not_lockable" type="tinyint"/>
            <column name="localized" type="tinyint"/>
            <column name="implementation" type="varchar(250)"/>
            <column name="spec" type="text" defaultValue="{}">
                <constraints nullable="false"/>
            </column>
            <column name="checksum" type="varchar(50)"/>
            <column name="hash" type="varchar(50)"/>
            <column name="generation" type="int" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="major_rev" type="varchar(50)" defaultValue="A">
                <constraints nullable="false"/>
            </column>
            <column name="minor_rev" type="varchar(50)"/>
            <column name="is_current" type="tinyint" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="permission_id" type="varchar(36)"/>
            <column name="locale" type="varchar(50)">
                <constraints foreignKeyName="core_items_locale_fk" references="core_locales(name)"/>
            </column>
            <column name="lifecycle_id" type="varchar(36)">
                <constraints foreignKeyName="core_items_lifecycle_fk" references="core_lifecycles(id)"/>
            </column>
            <column name="state" type="varchar(50)"/>
            <column name="created_at" type="datetime">
                <constraints nullable="false"/>
            </column>
            <column name="created_by_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="updated_at" type="datetime"/>
            <column name="updated_by_id" type="varchar(36)"/>
            <column name="locked_by_id" type="varchar(36)"/>
        </createTable>

<!--        <createIndex tableName="core_items" indexName="core_items_config_idx">-->
<!--            <column name="config_id"/>-->
<!--        </createIndex>-->

        <createIndex tableName="core_items" indexName="core_items_permission_idx">
            <column name="permission_id"/>
        </createIndex>

<!--        <createIndex tableName="core_items" indexName="core_items_major_rev_idx">-->
<!--            <column name="major_rev"/>-->
<!--        </createIndex>-->

<!--        <createIndex tableName="core_items" indexName="core_items_is_current_idx">-->
<!--            <column name="is_current"/>-->
<!--        </createIndex>-->

        <!--core_sequences-->
        <createTable tableName="core_sequences">
            <column name="id" type="varchar(36)">
                <constraints primaryKey="true" primaryKeyName="core_sequences_pk"/>
            </column>
            <column name="config_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="name" type="varchar(50)">
                <constraints nullable="false" unique="true" uniqueConstraintName="core_sequences_name_uk"/>
            </column>
            <column name="display_name" type="varchar(50)"/>
            <column name="prefix" type="varchar(50)"/>
            <column name="suffix" type="varchar(50)"/>
            <column name="initial_value" type="int" defaultValue="0">
                <constraints nullable="false"/>
            </column>
            <column name="current_value" type="int"/>
            <column name="step" type="int" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="pad_with" type="char(1)"/>
            <column name="pad_to" type="int"/>
            <column name="generation" type="int" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="major_rev" type="varchar(50)" defaultValue="A">
                <constraints nullable="false"/>
            </column>
            <column name="minor_rev" type="varchar(50)"/>
            <column name="is_current" type="tinyint" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="permission_id" type="varchar(36)"/>
            <column name="locale" type="varchar(50)">
                <constraints foreignKeyName="core_sequences_locale_fk" references="core_locales(name)"/>
            </column>
            <column name="lifecycle_id" type="varchar(36)">
                <constraints foreignKeyName="core_sequences_lifecycle_fk" references="core_lifecycles(id)"/>
            </column>
            <column name="state" type="varchar(50)"/>
            <column name="created_at" type="datetime">
                <constraints nullable="false"/>
            </column>
            <column name="created_by_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="updated_at" type="datetime"/>
            <column name="updated_by_id" type="varchar(36)"/>
            <column name="locked_by_id" type="varchar(36)"/>
        </createTable>

<!--        <createIndex tableName="core_sequences" indexName="core_sequences_config_idx">-->
<!--            <column name="config_id"/>-->
<!--        </createIndex>-->

        <createIndex tableName="core_sequences" indexName="core_sequences_permission_idx">
            <column name="permission_id"/>
        </createIndex>

<!--        <createIndex tableName="core_sequences" indexName="core_sequences_major_rev_idx">-->
<!--            <column name="major_rev"/>-->
<!--        </createIndex>-->

<!--        <createIndex tableName="core_sequences" indexName="core_sequences_is_current_idx">-->
<!--            <column name="is_current"/>-->
<!--        </createIndex>-->

        <!--core_media-->
        <createTable tableName="core_media">
            <column name="id" type="varchar(36)">
                <constraints primaryKey="true" primaryKeyName="core_media_pk"/>
            </column>
            <column name="config_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="filename" type="varchar(100)">
                <constraints nullable="false"/>
            </column>
            <column name="label" type="varchar(50)"/>
            <column name="description" type="varchar(250)"/>
            <column name="file_size" type="int">
                <constraints nullable="false"/>
            </column>
            <column name="mimetype" type="varchar(100)">
                <constraints nullable="false"/>
            </column>
            <column name="path" type="varchar(500)">
                <constraints nullable="false"/>
            </column>
            <column name="checksum" type="varchar(50)">
                <constraints nullable="false"/>
            </column>
            <column name="generation" type="int" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="major_rev" type="varchar(50)" defaultValue="A">
                <constraints nullable="false"/>
            </column>
            <column name="minor_rev" type="varchar(50)"/>
            <column name="is_current" type="tinyint" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="permission_id" type="varchar(36)"/>
            <column name="locale" type="varchar(50)">
                <constraints foreignKeyName="core_media_locale_fk" references="core_locales(name)"/>
            </column>
            <column name="lifecycle_id" type="varchar(36)">
                <constraints foreignKeyName="core_media_lifecycle_fk" references="core_lifecycles(id)"/>
            </column>
            <column name="state" type="varchar(50)"/>
            <column name="created_at" type="datetime">
                <constraints nullable="false"/>
            </column>
            <column name="created_by_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="updated_at" type="datetime"/>
            <column name="updated_by_id" type="varchar(36)"/>
            <column name="locked_by_id" type="varchar(36)"/>
        </createTable>

<!--        <createIndex tableName="core_media" indexName="core_media_config_idx">-->
<!--            <column name="config_id"/>-->
<!--        </createIndex>-->

        <createIndex tableName="core_media" indexName="core_media_permission_idx">
            <column name="permission_id"/>
        </createIndex>

<!--        <createIndex tableName="core_media" indexName="core_media_major_rev_idx">-->
<!--            <column name="major_rev"/>-->
<!--        </createIndex>-->

<!--        <createIndex tableName="core_media" indexName="core_media_is_current_idx">-->
<!--            <column name="is_current"/>-->
<!--        </createIndex>-->

        <!--core_allowed_lifecycles-->
        <createTable tableName="core_allowed_lifecycles">
            <column name="id" type="varchar(36)">
                <constraints primaryKey="true" primaryKeyName="core_allowed_lifecycles_pk"/>
            </column>
            <column name="config_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="label" type="varchar(50)"/>
            <column name="sort_order" type="int"/>
            <column name="is_default" type="tinyint"/>
            <column name="source_id" type="varchar(36)">
                <constraints nullable="false" foreignKeyName="core_allowed_lifecycles_source_fk" references="core_items(id)"/>
            </column>
            <column name="target_id" type="varchar(36)">
                <constraints nullable="false" foreignKeyName="core_allowed_lifecycles_target_fk" references="core_lifecycles(id)"/>
            </column>
            <column name="generation" type="int" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="major_rev" type="varchar(50)" defaultValue="A">
                <constraints nullable="false"/>
            </column>
            <column name="minor_rev" type="varchar(50)"/>
            <column name="is_current" type="tinyint" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="permission_id" type="varchar(36)"/>
            <column name="locale" type="varchar(50)">
                <constraints foreignKeyName="core_allowed_lifecycles_locale_fk" references="core_locales(name)"/>
            </column>
            <column name="lifecycle_id" type="varchar(36)">
                <constraints foreignKeyName="core_allowed_lifecycles_lifecycle_fk" references="core_lifecycles(id)"/>
            </column>
            <column name="state" type="varchar(50)"/>
            <column name="created_at" type="datetime">
                <constraints nullable="false"/>
            </column>
            <column name="created_by_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="updated_at" type="datetime"/>
            <column name="updated_by_id" type="varchar(36)"/>
            <column name="locked_by_id" type="varchar(36)"/>
        </createTable>

        <addUniqueConstraint tableName="core_allowed_lifecycles" constraintName="core_allowed_lifecycles_source_target_uk" columnNames="source_id, target_id"/>

<!--        <createIndex tableName="core_allowed_lifecycles" indexName="core_allowed_lifecycles_config_idx">-->
<!--            <column name="config_id"/>-->
<!--        </createIndex>-->

        <createIndex tableName="core_allowed_lifecycles" indexName="core_allowed_lifecycles_permission_idx">
            <column name="permission_id"/>
        </createIndex>

<!--        <createIndex tableName="core_allowed_lifecycles" indexName="core_allowed_lifecycles_major_rev_idx">-->
<!--            <column name="major_rev"/>-->
<!--        </createIndex>-->

<!--        <createIndex tableName="core_allowed_lifecycles" indexName="core_allowed_lifecycles_is_current_idx">-->
<!--            <column name="is_current"/>-->
<!--        </createIndex>-->

        <!--core_schema_lock-->
        <createTable tableName="core_schema_lock">
            <column name="id" type="int">
                <constraints primaryKey="true" primaryKeyName="core_schema_lock_pk"/>
            </column>
            <column name="locked_by" type="varchar(255)"/>
            <column name="lock_until" type="datetime"/>
        </createTable>

        <!--BI-->
        <!--bi_datasets-->
        <createTable tableName="bi_datasets">
            <column name="id" type="varchar(36)">
                <constraints primaryKey="true" primaryKeyName="bi_datasets_pk"/>
            </column>
            <column name="config_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="name" type="varchar(50)">
                <constraints nullable="false" unique="true"  uniqueConstraintName="bi_datasets_name_uk"/>
            </column>
            <column name="datasource_id" type="varchar(36)">
                <constraints foreignKeyName="bi_datasets_datasource_fk" references="core_datasources(id)"/>
            </column>
            <column name="table_name" type="varchar(50)"/>
            <column name="query" type="text"/>
            <column name="cache_ttl" type="int"/>
            <column name="description" type="varchar(250)"/>
            <column name="spec" type="text" defaultValue="{}">
                <constraints nullable="false"/>
            </column>
            <column name="hash" type="varchar(50)"/>
            <column name="generation" type="int" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="major_rev" type="varchar(50)" defaultValue="A">
                <constraints nullable="false"/>
            </column>
            <column name="minor_rev" type="varchar(50)"/>
            <column name="is_current" type="tinyint" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="permission_id" type="varchar(36)"/>
            <column name="locale" type="varchar(50)">
                <constraints foreignKeyName="bi_datasets_locale_fk" references="core_locales(name)"/>
            </column>
            <column name="lifecycle_id" type="varchar(36)">
                <constraints foreignKeyName="bi_datasets_lifecycle_fk" references="core_lifecycles(id)"/>
            </column>
            <column name="state" type="varchar(50)"/>
            <column name="created_at" type="datetime">
                <constraints nullable="false"/>
            </column>
            <column name="created_by_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="updated_at" type="datetime"/>
            <column name="updated_by_id" type="varchar(36)"/>
            <column name="locked_by_id" type="varchar(36)"/>
        </createTable>

<!--        <createIndex tableName="bi_datasets" indexName="bi_datasets_config_idx">-->
<!--            <column name="config_id"/>-->
<!--        </createIndex>-->

        <createIndex tableName="bi_datasets" indexName="bi_datasets_permission_idx">
            <column name="permission_id"/>
        </createIndex>

<!--        <createIndex tableName="bi_datasets" indexName="bi_datasets_major_rev_idx">-->
<!--            <column name="major_rev"/>-->
<!--        </createIndex>-->

<!--        <createIndex tableName="bi_datasets" indexName="bi_datasets_is_current_idx">-->
<!--            <column name="is_current"/>-->
<!--        </createIndex>-->

        <!--bi_dashboards-->
        <createTable tableName="bi_dashboards">
            <column name="id" type="varchar(36)">
                <constraints primaryKey="true" primaryKeyName="bi_dashboards_pk"/>
            </column>
            <column name="config_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="name" type="varchar(50)">
                <constraints nullable="false" unique="true" uniqueConstraintName="bi_dashboards_name_uk"/>
            </column>
            <column name="is_public" type="tinyint" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="spec" type="text" defaultValue="{}">
                <constraints nullable="false"/>
            </column>
            <column name="hash" type="varchar(50)"/>
            <column name="generation" type="int" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="major_rev" type="varchar(50)" defaultValue="A">
                <constraints nullable="false"/>
            </column>
            <column name="minor_rev" type="varchar(50)"/>
            <column name="is_current" type="tinyint" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="permission_id" type="varchar(36)"/>
            <column name="locale" type="varchar(50)">
                <constraints foreignKeyName="bi_dashboards_locale_fk" references="core_locales(name)"/>
            </column>
            <column name="lifecycle_id" type="varchar(36)">
                <constraints foreignKeyName="bi_dashboards_lifecycle_fk" references="core_lifecycles(id)"/>
            </column>
            <column name="state" type="varchar(50)"/>
            <column name="created_at" type="datetime">
                <constraints nullable="false"/>
            </column>
            <column name="created_by_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="updated_at" type="datetime"/>
            <column name="updated_by_id" type="varchar(36)"/>
            <column name="locked_by_id" type="varchar(36)"/>
        </createTable>

<!--        <createIndex tableName="bi_dashboards" indexName="bi_dashboards_config_idx">-->
<!--            <column name="config_id"/>-->
<!--        </createIndex>-->

        <createIndex tableName="bi_dashboards" indexName="bi_dashboards_permission_idx">
            <column name="permission_id"/>
        </createIndex>

<!--        <createIndex tableName="bi_dashboards" indexName="bi_dashboards_major_rev_idx">-->
<!--            <column name="major_rev"/>-->
<!--        </createIndex>-->

<!--        <createIndex tableName="bi_dashboards" indexName="bi_dashboards_is_current_idx">-->
<!--            <column name="is_current"/>-->
<!--        </createIndex>-->
    </changeSet>

    <changeSet id="2023-10-17-dashboard-category" author="bchernysh">
        <!--bi_dashboard_categories-->
        <createTable tableName="bi_dashboard_categories">
            <column name="id" type="varchar(36)">
                <constraints primaryKey="true" primaryKeyName="bi_dashboard_categories_pk"/>
            </column>
            <column name="config_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="name" type="varchar(50)">
                <constraints nullable="false" unique="true" uniqueConstraintName="bi_dashboard_categories_name_uk"/>
            </column>
            <column name="icon" type="varchar(50)"/>
            <column name="generation" type="int" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="major_rev" type="varchar(50)" defaultValue="A">
                <constraints nullable="false"/>
            </column>
            <column name="minor_rev" type="varchar(50)"/>
            <column name="is_current" type="tinyint" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="permission_id" type="varchar(36)"/>
            <column name="locale" type="varchar(50)">
                <constraints foreignKeyName="bi_dashboard_categories_locale_fk" references="core_locales(name)"/>
            </column>
            <column name="lifecycle_id" type="varchar(36)">
                <constraints foreignKeyName="bi_dashboard_categories_lifecycle_fk" references="core_lifecycles(id)"/>
            </column>
            <column name="state" type="varchar(50)"/>
            <column name="created_at" type="datetime">
                <constraints nullable="false"/>
            </column>
            <column name="created_by_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="updated_at" type="datetime"/>
            <column name="updated_by_id" type="varchar(36)"/>
            <column name="locked_by_id" type="varchar(36)"/>
        </createTable>

        <createIndex tableName="bi_dashboard_categories" indexName="bi_dashboard_categories_permission_idx">
            <column name="permission_id"/>
        </createIndex>

        <!--bi_dashboard_category_map-->
        <createTable tableName="bi_dashboard_category_map">
            <column name="id" type="varchar(36)">
                <constraints primaryKey="true" primaryKeyName="bi_dashboard_category_map_pk"/>
            </column>
            <column name="config_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="sort_order" type="int"/>
            <column name="label" type="varchar(50)"/>
            <column name="source_id" type="varchar(36)">
                <constraints nullable="false" foreignKeyName="bi_dashboard_category_map_source_fk" references="bi_dashboards(id)"/>
            </column>
            <column name="target_id" type="varchar(36)">
                <constraints nullable="false" foreignKeyName="bi_dashboard_category_map_target_fk" references="bi_dashboard_categories(id)"/>
            </column>
            <column name="generation" type="int" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="major_rev" type="varchar(50)" defaultValue="A">
                <constraints nullable="false"/>
            </column>
            <column name="minor_rev" type="varchar(50)"/>
            <column name="is_current" type="tinyint" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="permission_id" type="varchar(36)"/>
            <column name="locale" type="varchar(50)">
                <constraints foreignKeyName="bi_dashboard_category_map_locale_fk" references="core_locales(name)"/>
            </column>
            <column name="lifecycle_id" type="varchar(36)">
                <constraints foreignKeyName="bi_dashboard_category_map_lifecycle_fk" references="core_lifecycles(id)"/>
            </column>
            <column name="state" type="varchar(50)"/>
            <column name="created_at" type="datetime">
                <constraints nullable="false"/>
            </column>
            <column name="created_by_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="updated_at" type="datetime"/>
            <column name="updated_by_id" type="varchar(36)"/>
            <column name="locked_by_id" type="varchar(36)"/>
        </createTable>

        <addUniqueConstraint tableName="bi_dashboard_category_map" constraintName="bi_dashboard_category_map_source_target_uk" columnNames="source_id, target_id"/>

        <createIndex tableName="bi_dashboard_category_map" indexName="bi_dashboard_category_map_permission_idx">
            <column name="permission_id"/>
        </createIndex>

        <!--bi_dashboard_category_hierarchy-->
        <createTable tableName="bi_dashboard_category_hierarchy">
            <column name="id" type="varchar(36)">
                <constraints primaryKey="true" primaryKeyName="bi_dashboard_category_hierarchy_pk"/>
            </column>
            <column name="config_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="label" type="varchar(50)"/>
            <column name="sort_order" type="int"/>
            <column name="source_id" type="varchar(36)">
                <constraints nullable="false" foreignKeyName="bi_dashboard_category_hierarchy_source_fk" references="bi_dashboard_categories(id)"/>
            </column>
            <column name="target_id" type="varchar(36)">
                <constraints nullable="false" foreignKeyName="bi_dashboard_category_hierarchy_target_fk" references="bi_dashboard_categories(id)"/>
            </column>
            <column name="generation" type="int" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="major_rev" type="varchar(50)" defaultValue="A">
                <constraints nullable="false"/>
            </column>
            <column name="minor_rev" type="varchar(50)"/>
            <column name="is_current" type="tinyint" defaultValue="1">
                <constraints nullable="false"/>
            </column>
            <column name="permission_id" type="varchar(36)"/>
            <column name="locale" type="varchar(50)">
                <constraints foreignKeyName="bi_dashboard_category_hierarchy_locale_fk" references="core_locales(name)"/>
            </column>
            <column name="lifecycle_id" type="varchar(36)">
                <constraints foreignKeyName="bi_dashboard_category_hierarchy_lifecycle_fk" references="core_lifecycles(id)"/>
            </column>
            <column name="state" type="varchar(50)"/>
            <column name="created_at" type="datetime">
                <constraints nullable="false"/>
            </column>
            <column name="created_by_id" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
            <column name="updated_at" type="datetime"/>
            <column name="updated_by_id" type="varchar(36)"/>
            <column name="locked_by_id" type="varchar(36)"/>
        </createTable>

        <addUniqueConstraint tableName="bi_dashboard_category_hierarchy" constraintName="bi_dashboard_category_hierarchy_source_target_uk" columnNames="source_id, target_id"/>

        <createIndex tableName="bi_dashboard_category_hierarchy" indexName="bi_dashboard_category_hierarchy_permission_idx">
            <column name="permission_id"/>
        </createIndex>
    </changeSet>
</databaseChangeLog>
